class WeightRecord {
  final String id;
  final double weight; // 体重(kg)
  final double? waistCircumference; // 腰围(cm)
  final double? bmi; // 体质指数
  final double? bodyFatPercentage; // 体脂率
  final DateTime recordTime;
  final String? notes;

  WeightRecord({
    required this.id,
    required this.weight,
    this.waistCircumference,
    this.bmi,
    this.bodyFatPercentage,
    required this.recordTime,
    this.notes,
  });

  // 从JSON转换和转为JSON的方法
  factory WeightRecord.fromJson(Map<String, dynamic> json) {
    return WeightRecord(
      id: json['id'],
      weight: json['weight'],
      waistCircumference: json['waistCircumference'],
      bmi: json['bmi'],
      bodyFatPercentage: json['bodyFatPercentage'],
      recordTime: DateTime.parse(json['recordTime']),
      notes: json['notes'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'weight': weight,
      'waistCircumference': waistCircumference,
      'bmi': bmi,
      'bodyFatPercentage': bodyFatPercentage,
      'recordTime': recordTime.toIso8601String(),
      'notes': notes,
    };
  }
}
